

function getSettingState(binaryData){
	let state1 = []
	// 转换为二进制字符串（确保长度为16位）
	//const binaryData = ('0000' + parseInt(hexData, 16).toString(2)).slice(-16);
	//console.log(`二进制数据: ${binaryData}`);
	// 解析每个位的信息
	const bitInfo = [
	    { name: 'Bit0', value: binaryData[0], desc: ['总压过放告警开', '总压过放告警关'] },
	    { name: 'Bit1', value: binaryData[1], desc: ['过流告警开', '过流告警关'] },
	    { name: 'Bit2', value: binaryData[2], desc: ['过温告警开', '过温告警关'] },
	    { name: 'Bit3', value: binaryData[3], desc: ['MOS过温告警开', 'MOS过温告警关'] },
	    { name: 'Bit4', value: binaryData[4], desc: ['电芯不均衡告警开', '电芯不均衡告警关'] },
	    { name: 'Bit5', value: binaryData[5], desc: ['环境温度告警开', '环境温度告警关'] },
	    { name: 'Bit6', value: binaryData[6], desc: ['SOC低告警开', 'SOC低告警关'] },
	    { name: 'Bit7', value: binaryData[7], desc: ['加热风扇温度控制开', '加热风扇温度控制关'] },
	    { name: 'Bit8', value: binaryData[8], desc: ['总电压保护开', '总电压保护关'] },
	    { name: 'Bit9~Bit11', value: binaryData.substring(9, 12), desc: '无' },
	    { name: 'Bit12', value: binaryData[12], desc: ['静态均衡开', '静态均衡关'] },
	    { name: 'Bit13~Bit15', value: binaryData.substring(13, 16), desc: '无' }
	];
	
	// 输出解析结果
	// bitInfo.forEach(info => {
	//     if (Array.isArray(info.desc)) {
	// 		info.name = info.desc[parseInt(info.value)===0?1:0]
	//         //console.log(`${info.name}: ${info.value} - ${info.desc[parseInt(info.value)===0?1:0]}`);
	//     } else {
	// 		info.name =  ''
	//         //console.log(`${info.name}: ${info.value} - ${info.desc}`);
	//     }
	// });
	return bitInfo;
}

function getALARMState(binaryData){
	let state1 = []
	// 转换为二进制字符串（确保长度为16位）
	//const binaryData = ('0000' + parseInt(hexData, 16).toString(2)).slice(-16);
	// 解析每个位的信息
	const bitInfo = [
	    { name: 'Bit0', value: binaryData[0], desc: ['电芯过放告警', '无'] },
	    { name: 'Bit1', value: binaryData[1], desc: ['总过放告警', '无'] },
	    { name: 'Bit2', value: binaryData[2], desc: ['电芯过压告警', '无'] },
	    { name: 'Bit3', value: binaryData[3], desc: ['总过压告警', '无'] },
	    { name: 'Bit4', value: binaryData[4], desc: ['放电过流告警', '无'] },
	    { name: 'Bit5', value: binaryData[5], desc: ['充电过流告警', '无'] },
	    { name: 'Bit6', value: binaryData[6], desc: ['放电过温告警', '无'] },
	    { name: 'Bit7', value: binaryData[7], desc: ['充电过温告警', '无'] },
	    { name: 'Bit8', value: binaryData[8], desc: ['环境高温告警', '无'] },
	    { name: 'Bit9', value: binaryData[9], desc: ['环境低温告警', '无'] },
	    { name: 'Bit10', value: binaryData[10], desc: ['SOC低告警', '无'] },
	    { name: 'Bit11', value: binaryData[11], desc: ['MOS高温告警', '无'] },
	    { name: 'Bit12', value: binaryData[12], desc: ['压差报警', '无'] },
	    { name: 'Bit13', value: binaryData[13], desc: ['温差报警', '无'] },
	    { name: 'Bit14~Bit15', value: binaryData.substring(14, 16), desc: '无' }
	];

	
	// 输出解析结果
	// bitInfo.forEach(info => {
	//     if (Array.isArray(info.desc)) {
	// 		info.name = info.desc[parseInt(info.value)===0?1:0]
	//         //console.log(`${info.name}: ${info.value} - ${info.desc[parseInt(info.value)===0?1:0]}`);
	//     } else {
	// 		info.name =  ''
	//         //console.log(`${info.name}: ${info.value} - ${info.desc}`);
	//     }
	// });
	//console.log('getALARMState',bitInfo);
	return bitInfo;
}

function getState(binaryData){
	let state1 = []
	// 转换为二进制字符串（确保长度为16位）
	//const binaryData = ('0000' + parseInt(hexData, 16).toString(2)).slice(-16);
	//console.log(`二进制数据: ${binaryData}`);
	// 解析每个位的信息
	const bitInfo = [
	    { name: 'Bit0', value: binaryData[0], desc: '无' },
	    { name: 'Bit1', value: binaryData[1], desc: ['放电MOS开', '放电MOS关'] },
	    { name: 'Bit2', value: binaryData[2], desc: ['充电MOS开', '充电MOS关'] },
	    { name: 'Bit3~Bit7', value: binaryData.substring(3, 8), desc: '无' },
	    { name: 'Bit8', value: binaryData[8], desc: ['温度采集失效/传感器故障', '无'] },
	    { name: 'Bit9', value: binaryData[9], desc: ['电压采集失效/断线故障', '无'] },
	    { name: 'Bit10', value: binaryData[10], desc: ['放电MOS失效', '无'] },
	    { name: 'Bit11', value: binaryData[11], desc: ['充电MOS失效', '无'] },
	    { name: 'Bit12', value: binaryData[12], desc: ['电芯不均衡告警', '无'] },
	    { name: 'Bit13', value: binaryData[13], desc: '无' },
	    { name: 'Bit14', value: binaryData[14], desc: ['放电低温告警', '无'] },
	    { name: 'Bit15', value: binaryData[15], desc: ['充电低温告警', '无'] }
	];
	
	// 输出解析结果
	// bitInfo.forEach(info => {
	//     if (Array.isArray(info.desc)) {
	// 		info.name = info.desc[parseInt(info.value)===0?1:0]
	//         //console.log(`${info.name}: ${info.value} - ${info.desc[parseInt(info.value)===0?1:0]}`);
	//     } else {
	// 		info.name =  ''
	//        // console.log(`${info.name}: ${info.value} - ${info.desc}`);
	//     }
	// });
	return bitInfo;
}


function getState1(binaryData){
	let state1 = []
	// 转换为二进制字符串（确保长度为16位）
	//const binaryData = ('0000' + parseInt(hexData, 16).toString(2)).slice(-16);
	//console.log(`二进制数据: ${binaryData}`);
	// 解析每个位的信息
	const bitInfo = [
	    { name: 'Bit0', value: binaryData[0], desc: ['正在放电', '无放电'] },
	    { name: 'Bit1', value: binaryData[1], desc: ['正在充电', '无充电'] },
	    { name: 'Bit2', value: binaryData[2], desc: ['充电器已连接', '充电器未连接'] },
	    { name: 'Bit3', value: binaryData[3], desc: ['过流值 x4', '过流值 x1'] },
	    { name: 'Bit4', value: binaryData[4], desc: ['有MOS温度', '无MOS温度'] },
	    { name: 'Bit5', value: binaryData[5], desc: ['有环境温度', '无环境温度'] },
	    { name: 'Bit6~Bit7', value: binaryData.substring(6, 8), desc: '无' },
	    { name: 'Bit8', value: binaryData[8], desc: ['电芯过压', '无电芯过压'] },
	    { name: 'Bit9', value: binaryData[9], desc: ['总压过压', '无总压过压'] },
	    { name: 'Bit10~Bit11', value: binaryData.substring(10, 12), desc: '无' },
	    { name: 'Bit12', value: binaryData[12], desc: ['充满保护', '无充满保护'] },
	    { name: 'Bit12~Bit15', value: binaryData.substring(12, 16), desc: '无' }
	];
	
	// 输出解析结果
	// bitInfo.forEach(info => {
	//     if (Array.isArray(info.desc)) {
	// 		info.name = info.desc[parseInt(info.value)===0?1:0]
	//         //console.log(`${info.name}: ${info.value} - ${info.desc[parseInt(info.value)===0?1:0]}`);
	//     } else {
	// 		info.name =  ''
	//         //console.log(`${info.name}: ${info.value} - ${info.desc}`);
	//     }
	// });
	//console.log(state1);
	return bitInfo;
}

function getState2(binaryData){
	let state1 = []
	// 转换为二进制字符串（确保长度为16位）
	//const binaryData = ('0000' + parseInt(hexData, 16).toString(2)).slice(-16);
	//console.log(`二进制数据: ${binaryData}`);
	// 解析每个位的信息
	const bitInfo = [
	    { name: 'Bit0', value: binaryData[0], desc: ['电芯欠压', '无电芯欠压'] },
	    { name: 'Bit1', value: binaryData[1], desc: ['总压欠压', '无总压欠压'] },
	    { name: 'Bit2', value: binaryData[2], desc: ['压差大保护', '无保护'] },
	    { name: 'Bit3~Bit7', value: binaryData.substring(3, 8), desc: '无' },
	    { name: 'Bit8', value: binaryData[8], desc: ['充电高温保护', '无充电高温保护'] },
	    { name: 'Bit9', value: binaryData[9], desc: ['充电低温保护', '无充电低温保护'] },
	    { name: 'Bit10', value: binaryData[10], desc: ['MOS 高温保护', '无 MOS 高温保护'] },
	    { name: 'Bit11', value: binaryData[11], desc: '无' },
	    { name: 'Bit12', value: binaryData[12], desc: ['放电高温保护', '无放电高温保护'] },
	    { name: 'Bit13', value: binaryData[13], desc: ['放电低温保护', '无放电低温保护'] },
	    { name: 'Bit14', value: binaryData[14], desc: ['温差大保护', '无保护'] },
	    { name: 'Bit15', value: binaryData[15], desc: '无' }
	];
	
	// 输出解析结果
	// bitInfo.forEach(info => {
	//     if (Array.isArray(info.desc)) {
	// 		info.name = info.desc[parseInt(info.value)===0?1:0]
	//         //console.log(`${info.name}: ${info.value} - ${info.desc[parseInt(info.value)===0?1:0]}`);
	//     } else {
	// 		info.name =  ''
	//         //console.log(`${info.name}: ${info.value} - ${info.desc}`);
	//     }
	// });
	//console.log(state1);
	return bitInfo;
}

function getState3(binaryData){
	let state1 = []
	// 转换为二进制字符串（确保长度为16位）
	//const binaryData = ('0000' + parseInt(hexData, 16).toString(2)).slice(-16);
	//console.log(`二进制数据: ${binaryData}`);
	// 解析每个位的信息
	const bitInfo = [
	    { name: 'Bit0', value: binaryData[0], desc: ['放电短路保护', '无放电短路保护'] },
	    { name: 'Bit1', value: binaryData[1], desc: ['放电过流保护', '无放电过流保护'] },
	    { name: 'Bit2', value: binaryData[2], desc: ['充电过流保护', '无充电过流保护'] },
	    { name: 'Bit3', value: binaryData[3], desc: '无' },
	    { name: 'Bit4', value: binaryData[4], desc: ['环境高温保护', '无环境高温保护'] },
	    { name: 'Bit5', value: binaryData[5], desc: ['环境低温保护', '无环境低温保护'] },
	    { name: 'Bit6~Bit15', value: binaryData.substring(6, 16), desc: '无' }
	];
	
	// 输出解析结果
	// bitInfo.forEach(info => {
	//     if (Array.isArray(info.desc)) {
	// 		info.name = info.desc[parseInt(info.value)===0?1:0]
	//         //console.log(`${info.name}: ${info.value} - ${info.desc[parseInt(info.value)===0?1:0]}`);
	//     } else {
	// 		info.name =  ''
	//         //console.log(`${info.name}: ${info.value} - ${info.desc}`);
	//     }
	// });
	return bitInfo;
}

export default {
	getState:getState,
	getState1: getState1,
	getState2: getState2,
	getState3: getState3,
	getALARMState:getALARMState,
	getSettingState:getSettingState
}